package ywh.ui
{
	import com.yahoo.astra.fl.controls.Tree;
	import com.yahoo.astra.fl.controls.treeClasses.TNode;
	import com.yahoo.astra.fl.controls.treeClasses.TreeCellRenderer;
	import fl.controls.List;
	import fl.controls.listClasses.ListData;
	import fl.managers.StyleManager;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author 杨伟华
	 */
	public class MyTreeCellRenderer extends TreeCellRenderer
	{
		
		{
			StyleManager.setComponentStyle(MyTreeCellRenderer, "textFormat", new flash.text.TextFormat(null, 14, 0x006600));
		}
		
		private static var defaultStyles:Object = {upSkin: "TreeCellRenderer_Skin", downSkin: "TreeCellRenderer_Skin", overSkin: "TreeCellRenderer_Skin", disabledSkin: "TreeCellRenderer_Skin", selectedUpSkin: "TreeCellRenderer_SkinS", selectedDownSkin: "TreeCellRenderer_SkinS", selectedOverSkin: "TreeCellRenderer_SkinS", selectedDisabledSkin: "TreeCellRenderer_SkinS", closedBranchIcon: "TreeCellRenderer_closedBranchIcon", openBranchIcon: "TreeCellRenderer_openBranchIcon", leafIcon: "TreeCellRenderer_leafIcon", skinB: "TreeCellRenderer_SkinB", skinA: "TreeCellRenderer_SkinA", textFormat: null, disabledTextFormat: null, embedFonts: null, textPadding: 5, nodeIndent: 20, leftMargin: 5};
		
		public static function getStyleDefinition():Object
		{
			return mergeStyles(defaultStyles, TreeCellRenderer.getStyleDefinition());
		}
		
		public function MyTreeCellRenderer()
		{
		
		}
		
		override protected function drawTextFormat():void
		{
			super.drawTextFormat();
		}
		
		override public function setSharedStyle(name:String, style:Object):void
		{
			if (name == "textFormat")
			{
				super.setSharedStyle(name, style);
				return;
			}
			super.setSharedStyle(name, style);
		}
		
		override public function set listData(value:ListData):void
		{
			super.listData = value;
			var _listData:ListData = value;
			var data:Object = (_listData.owner as List).getItemAt(_listData.index) as TNode;
			label = (data.hasOwnProperty("orderLabel")?(data["orderLabel"] + "   " ):"")+_listData.label;
			if (_listData.index % 2)
			{
				setStyle("upSkin", getStyleValue("skinB"));
				setStyle("downSkin", getStyleValue("skinB"));
				setStyle("overSkin", getStyleValue("skinB"));
				setStyle("disabledSkin", getStyleValue("skinB"));
				setStyle("upSkin", getStyleValue("skinB"));
			}
			else
			{
				setStyle("upSkin", getStyleValue("skinA"));
				setStyle("downSkin", getStyleValue("skinA"));
				setStyle("overSkin", getStyleValue("skinA"));
				setStyle("disabledSkin", getStyleValue("skinA"));
				setStyle("upSkin", getStyleValue("skinA"));
			}
		}
	}

}